import { request } from '@/utils/request'

/**
 * 获取会话列表
 */
export const getSessionListApi = (userId) => {
  return request({
    url: '/chat/session_list',
    method: 'get',
    data: {
      userId
    }
  })
}

/**
 * 获取会话详情
 */
export const getSessionDetailApi = ({ sessionId, id, first }) => {
  return request({
    url: '/chat/session_detail',
    method: 'get',
    data: {
      sessionId,
      id,
      first
    }
  })
}

/**
 * 发送消息
 */
export const postMessageApi = ({ sessionId = null, fromId, toId, content, type, time }) => {
  return request({
    url: '/chat/send',
    method: 'post',
    data: {
      sessionId,
      fromId,
      toId,
      content,
      type,
      time
    }
  })
}

/**
 * 获取文件上传预签名URL
 */
export const getFilePreSignedUrlApi = (fileExt) => {
  return request({
    method: 'get',
    url: '/file/presigned/url',
    data: {
      fileExt
    }
  })
}

/**
 * 获取直传签名
 */
export const getOssSignatureApi = () => {
  return request({
    method: 'get',
    url: '/file/sign'
  })
}

/**
 * 多条消息置为已读
 */
export const putBatchReadApi = ({ sessionId, toId }) => {
  return request({
    url: '/chat/batch_read',
    method: 'post',
    data: {
      sessionId,
      toId // 发给谁的
    }
  })
}

/**
 * 单条消息置为已读
 */
export const putSingleReadApi = (id) => {
  return request({
    url: '/chat/single_read',
    method: 'post',
    data: {
      id
    }
  })
}

/**
 * 获取会话 id
 */
export const getSessionIdApi = ({ fromId, toId }) => {
  return request({
    method: 'get',
    url: '/chat/session_id',
    data: {
      fromId,
      toId
    }
  })
}
